
package Interface.Player;

import Jastermind.Player;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class JPanelPlayerStats extends JPanel{
    private Player player;
        public JPanelPlayerStats(Player Player){
            super();
            this.player=Player;
            this.setLayout(null);

        //*********************** JPSTATS ***********************
        int gamesPlayed=player.getGameWon()+player.getGameLost();

        JLabel jblTitre = new JLabel("Statistiques du joueur "+player.getName());
        jblTitre.setBounds(125,0, 200, 20);
        this.add(jblTitre);

        JLabel jblGamePlayed=new JLabel("Partie(s) jouée(s) : "+gamesPlayed);
        jblGamePlayed.setBounds(30,jblTitre.getY()+30,150, 20);
        this.add(jblGamePlayed);

        JLabel jblGameWon = new JLabel("Partie(s) gagnées) : "+player.getGameWon());
        jblGameWon.setBounds(220,jblTitre.getY()+30,150, 20);
        this.add(jblGameWon);

        JLabel jblGameLost = new JLabel("Partie(s) perdue(s) : "+player.getGameLost());
        jblGameLost.setBounds(jblGamePlayed.getX(),jblGamePlayed.getY()+30,150, 20);
        this.add(jblGameLost);

        JLabel jblPercentWon = new JLabel();
        jblPercentWon.setBounds(jblGameWon.getX(),jblGamePlayed.getY()+30,150, 20);
        jblPercentWon.setText("% victoire : ");
        if(gamesPlayed!=0){
            String percentWon=String.valueOf(100*(double)player.getGameWon()/(double)gamesPlayed);      
            jblPercentWon.setText(jblPercentWon.getText()+percentWon.substring(0,percentWon.indexOf(".")+2)+" %");
        }
        this.add(jblPercentWon);

        }
}
